# -*- coding: utf-8 -*-
import pandas as pd

g_tech = "6S考核表"


def read_sheet(ret, file_path, i):
    df = pd.read_excel(file_path, sheet_name=i)

    for index, row in df.iterrows():
        cmd = {}

        for name in df.columns:
            if name.find("设备编号") != -1:
                cmd["sn"] = row[name]

        ret.append(cmd)


if __name__ == '__main__':
    file_path = "./%s.xlsx" % g_tech

    doc = pd.ExcelFile(file_path)

    ret = []

    for i in doc.sheet_names:
        read_sheet(ret, file_path, i)

    for d in ret:
        sn = d["sn"]
        val = [
                ["设备编号", sn],
                [""],
                ["序号", "点栓项"],
                ]

        df = pd.DataFrame(val)

        with pd.ExcelWriter("./table/%s.xlsx" % sn) as f:
            df.to_excel(f)
